package com.example.springbootmybatis.service;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.springbootmybatis.dao.UserDao;
import com.example.springbootmybatis.entity.User;
import com.example.springbootmybatis.service.impl.ServiceUser;
import com.example.springbootmybatis.util.JwtUtil;
import com.example.springbootmybatis.vo.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ImplUserService implements ServiceUser {
  //public PageInfo<User> findBypage(Integer current, Integer pageSize);

  //public int insert(String s_name,String age,String email);

  //int update( String s_name, String age, String email, int id);

  //int delete(int id);
 // public PageInfo<User> findBypage(Integer current, Integer pageSize);
//
 //   public int insert(String s_name,String age,String email);
//
 //   int update( String s_name, String age, String email, int id);
//
 //   int delete(int id);
//
 //   Result selectAll(Integer currentPage, Integer pageSize);
  @Autowired
  private UserDao userDao;
    @Override
    public Result login(String name, String password) {
        QueryWrapper<User> wrapper = new QueryWrapper();
        wrapper.eq("name",name);
        wrapper.eq("password",password);
        List<User> users = userDao.selectList(wrapper);
        if (users.equals("[]")){
            return new Result(500,"登陆失败");
        }else {
            Map<String, Object> stringObjectHashMap = new HashMap<>();
            stringObjectHashMap.put("name",name);

            String token = JwtUtil.createToken(stringObjectHashMap);

            return new Result(200,"登录成功",token);
        }
    }

}


